package com.example.ysdt.controller;

import com.example.ysdt.Vo.ProductLabelVo;
import com.example.ysdt.entiey.Product;
import com.example.ysdt.entiey.ProductLabel;
import com.example.ysdt.service.ProductLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ProductLabel")
@Api(value = "商品标签接口", tags = {"商品标签接口"})
public class ProductLabelController {
    @Autowired
    ProductLabelService productLabelService;

    @PostMapping("queryProductLabel")
    @ApiOperation("查询商品标签")
    public Map<String, Object> queryProductLabel(@RequestBody ProductLabelVo productLabelVo) {
        Map<String, Object> Result = new HashMap<>();
        try {
            List<ProductLabel> products = productLabelService.queryProductLabel(productLabelVo);
            Result.put("code", 0);
            Result.put("message","查询成功");
            Result.put("data", products);
        } catch (Exception e) {
            Result.put("code",-1);
            Result.put("message","查询失败"+e.getMessage());
        }
        return Result;
    }

    @PostMapping("addProductLabel")
    @ApiOperation("新增关联商品")
    public Map<String, Object> addProductLabel(@RequestBody ProductLabelVo productLabelVo) {
        Map<String, Object> Result = new HashMap<>();
        try {
            List<ProductLabel> insertedLabels = productLabelService.addProductLabel(productLabelVo);
            Result.put("code", 0);
            Result.put("message","添加成功");
            Result.put("data", insertedLabels);
        } catch (Exception e) {
            Result.put("code",-1);
            Result.put("message","添加失败"+e.getMessage());
        }
        return Result;
    }

}
